var portLogin2 = chrome.extension.connect({name: 'page'+Math.random()});

var dislikes =
{
	preStartup: function()
	{
		var jQuery = window.jQuery.noConflict(true);
		if( typeof(jQuery.fn._init) == 'undefined') { jQuery.fn._init = jQuery.fn.init; }
		dislikes.jQuery = jQuery;
		
		dislikes.DOMstartup(document);
	},
	
	getURL: function(file)
	{
		return chrome.extension.getURL('skin/'+file);
	},
	
	processRequest: function(params, callback, context)
	{
		portLogin2.postMessage({params: params, callback: callback});
	},
	
	HTMLParser: function(str)
	{
		return '<div>' + str + '</div>';
	},
	
	analytics: function()
	{
		portLogin2.postMessage({analytics: true});
	},
	
	getAnswer: function(event)
	{
		dislikes.executeFunctionByName(event.callbackName, window, event.message);
	},
	
	executeFunctionByName: function(functionName, context /*, args */)
	{
		var args = Array.prototype.slice.call(arguments).splice(2);
		var namespaces = functionName.split(".");
		var func = namespaces.pop();
		for(var i = 0; i < namespaces.length; i++)
		{
			context = context[namespaces[i]];
		}
		return context[func].apply(this, args);
	}
};

portLogin2.onMessage.addListener(dislikes.getAnswer);

$(function()
{
	dislikes.preStartup();
	
});